/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.model.provider;

import java.util.List;

import com.siro.pm.I18nManager;
import com.siro.pm.PmApplication;
import com.siro.pm.model.DemandOrBug;
import com.siro.pm.model.Developer;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since DemandOrBugProvider.java v1.0
 */
public class DemandOrBugProvider {
	public static String BUG_PROPERTY_NAME = I18nManager.getMessage("bug.name");
	public static String BUG_PROPERTY_DESC = I18nManager.getMessage("bug.desc");
	public static String BUG_PROPERTY_PROJECT = I18nManager
			.getMessage("bug.project");
	public static String BUG_PROPERTY_LEVEL = I18nManager
			.getMessage("bug.level");
	public static String BUG_PROPERTY_CREATOR = I18nManager
			.getMessage("bug.creator");
	public static String BUG_PROPERTY_SOLVER = I18nManager
			.getMessage("bug.solver");
	public static String BUG_PROPERTY_STATUS = I18nManager
			.getMessage("bug.status");
	public static String BUG_PROPERTY_ADVISOR = I18nManager
			.getMessage("bug.advisor");
	public static String BUG_PROPERTY_RESULT = I18nManager
			.getMessage("bug.result");
	public static String BUG_PROPERTY_CREATETIME = I18nManager
			.getMessage("bug.createtime");
	public static String BUG_PROPERTY_CLOSETIME = I18nManager
			.getMessage("bug.closetime");

	public static final String[] BUG_STATUS_DATA = {
			I18nManager.getMessage("bug.status.draft"),
			I18nManager.getMessage("bug.status.commit"),
			I18nManager.getMessage("bug.status.dispatch"),
			I18nManager.getMessage("bug.status.closed"),
			I18nManager.getMessage("bug.status.complete"),
	};
	public static final String[] BUG_LEVEL_DATA = {
			I18nManager.getMessage("bug.level.normal"),
			I18nManager.getMessage("bug.level.urgent"),

	};

	static IndexedContainer bugsContainer;
	static {
		bugsContainer = new IndexedContainer();
		bugsContainer.addContainerProperty(BUG_PROPERTY_NAME, String.class, "");
		bugsContainer.addContainerProperty(BUG_PROPERTY_PROJECT, String.class,
				"");
		bugsContainer.addContainerProperty(BUG_PROPERTY_STATUS, String.class,
				"");
		bugsContainer
				.addContainerProperty(BUG_PROPERTY_LEVEL, String.class, "");
		bugsContainer.addContainerProperty(BUG_PROPERTY_CREATOR, String.class,
				"");
		bugsContainer.addContainerProperty(BUG_PROPERTY_SOLVER, String.class,
				"");
		bugsContainer.addContainerProperty(BUG_PROPERTY_ADVISOR, String.class,
				"");
		// bugsContainer.addContainerProperty(BUG_PROPERTY_RESULT, String.class,
		// "");
		bugsContainer.addContainerProperty(BUG_PROPERTY_CREATETIME,
				String.class, "");
		// bugsContainer.addContainerProperty(BUG_PROPERTY_CLOSETIME,
		// String.class, "");
	}

	public static IndexedContainer getBugsData(List<DemandOrBug> bugs) {
		bugsContainer.removeAllItems();
		if (bugs != null) {
			for (DemandOrBug bug : bugs) {
				Item item = bugsContainer.addItem(bug);
				item.getItemProperty(BUG_PROPERTY_NAME).setValue(bug.getName());
				item.getItemProperty(BUG_PROPERTY_PROJECT).setValue(
						bug.getProject().getName());
				item.getItemProperty(BUG_PROPERTY_LEVEL).setValue(
						bug.getLevel());
				item.getItemProperty(BUG_PROPERTY_CREATOR).setValue(
						bug.getCreator().getName());
				item.getItemProperty(BUG_PROPERTY_SOLVER).setValue(
						bug.getSolver().getName());
				item.getItemProperty(BUG_PROPERTY_STATUS).setValue(
						bug.getStatus());
				item.getItemProperty(BUG_PROPERTY_ADVISOR).setValue(
						bug.getAdvisor().getName());
				// item.getItemProperty(BUG_PROPERTY_RESULT).setValue(bug.getResult());
				item.getItemProperty(BUG_PROPERTY_CREATETIME).setValue(
						bug.getCreatetime());
				// item.getItemProperty(BUG_PROPERTY_CLOSETIME).setValue(
				// bug.getCreatetime());
			}
		}
		return bugsContainer;
	}

	public static IndexedContainer getBugsData() {
		bugsContainer.removeAllItems();
		List<DemandOrBug> bugs = getDemandOrBugsData();
		return getBugsData(bugs);
	}

	public static List<DemandOrBug> getDemandOrBugsData() {
		return DemandOrBug.getDemandOrBugs((Developer) PmApplication
				.getDefault().getUser());
	}
}
